#include "GAF_Layout.h"

namespace GAF
{
	Layout::Layout()
	{
	}

	Layout::~Layout()
	{
	}

	void Layout::Destroy()
	{
		m_mapGraphicses.clear();

		OnDestroy();
	}

	GAF_CGraphics* Layout::GetGraphicsByName(STD_STRING strGraphicsName, int nParam1, int nParam2)
	{
		return GetGraphics(strGraphicsName);
	}

	void Layout::AddGraphics(Graphics* pGraphics, bool isBack)
	{
		GAF_CHECK(pGraphics != NULL);

		// 检查并记录关键内容
		CheckGraphics(pGraphics);

		SUPER(Face)->AddGraphics(pGraphics, isBack);
	}

	Graphics* Layout::GetGraphics(STD_STRING strGraphicsName)
	{
		GraphicsMap::const_iterator _cit = m_mapGraphicses.find(strGraphicsName);
		if(_cit == m_mapGraphicses.end())
			return NULL;
		return _cit->second;
	}

	void Layout::CheckGraphics(Graphics* pGraphics)
	{
		static STD_STRING s_strGraphicsName;

		s_strGraphicsName = pGraphics->GetGraphicsName_a();
		if(s_strGraphicsName != "")
		{
			GraphicsMap::const_iterator _cit = m_mapGraphicses.find(s_strGraphicsName);
			if(_cit == m_mapGraphicses.end())
			{
				m_mapGraphicses.insert(GraphicsMap::value_type(s_strGraphicsName, pGraphics));
			}
		}

		FOREACH_P(Graphics, _pG, pGraphics)
		{
			CheckGraphics(_pG);
		}
	}
}
